﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;
using System.Globalization;

namespace BDSim
{
    /// <summary>
    /// UTC时间转换到指定字符串
    /// </summary>
    public class UTCTimeToString : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            string CurTime = "";
            if (value is UTCTimeClass)
            {
                UTCTimeClass ThisTime = (UTCTimeClass)value;
                CurTime = string.Format("{0}-{1}-{2} {3}:{4}:{5}", ThisTime.Year.ToString(), ThisTime.Mon.ToString("00"), ThisTime.Day.ToString("00"), ThisTime.Hour.ToString("00"), ThisTime.Min.ToString("00"), ThisTime.Sec.ToString("00"));
            }
            return CurTime;
        }
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            UTCTimeClass ThisTime = new UTCTimeClass();
            DateTime time = new DateTime();
            if (DateTime.TryParse(value.ToString(), out time))
            {
                ThisTime.year = time.Year;
                ThisTime.mon = time.Month;
                ThisTime.day = time.Day;
                ThisTime.hour = time.Hour;
                ThisTime.min = time.Minute;
                ThisTime.sec = time.Second;
            }
            else
            {

            }
            return ThisTime;
        }
    }
}
